<?php
	class models_chitietnhap extends connect{
		function _listCTNhap(){
			$sql = 'SELECT MaCTN, MaHang, MaMH, DonGiaNhap, SoLuongNhap, NgayNhap
					FROM chitietnhap';
			$this->query_db($sql);
			return $this->fetchAll();
		}
		function _getHang(){
			$sql = 'SELECT MaHang, TenHang
					FROM hang';
			$this->query_db($sql);
			return  $this->fetchAll();
		}
		function _getMatHang(){
			$sql = 'SELECT MaMH, TenMH 
					FROM mathang';
			$this->query_db($sql);
			return  $this->fetchAll();
		}
		function _addCTNhap($MaHang, $MaMH, $DonGiaNhap, $SoLuongNhap, $NgayNhap){
			$sql = "INSERT INTO chitietnhap VALUES ('','$MaHang','$MaMH','$DonGiaNhap','$SoLuongNhap',$NgayNhap)";
			$this->query_db($sql);
		}
		function _delCTNhap($id){
			$sql = "DELETE 
					FROM chitietnhap
					WHERE MaCTN = '$id'";
			$this->query_db($sql);
		}
		function _getCTNhap($id){
			$sql = "SELECT MaCTN, MaHang, MaMH, DonGiaNhap, SoLuongNhap, NgayNhap
					FROM chitietnhap
					WHERE MaCTN = '$id'";
			$this->query_db($sql);
			return $this->fetchOne();
		}
		function _editCTNhap($MaHang, $MaMH, $DonGiaNhap, $SoLuongNhap, $NgayNhap, $id){
			$sql = "UPDATE chitietnhap
					SET 
						MaHang = '$MaHang', 
						MaMH = '$MaMH', 
						DonGiaNhap = '$DonGiaNhap', 
						SoLuongNhap = '$SoLuongNhap',
						NgayNhap = '$NgayNhap'
					WHERE MaCTN = '$id'";
			$this->query_db($sql);
		}
	}
	
?>